<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>

	<div id="formArea">

		<table class="table">
			<tr>
				<td class="required">仓库名称</td>
				<td><input type="text" class="input" autocomplete="off" name="name"/></td>
			</tr>
			<tr>
				<td>所属机构</td>
				<td><div id="companyId"></div></td>
			</tr>
			<tr>
				<td>责任人</td>
				<td><input type="text" class="input" autocomplete="off" name="contact"/></td>
			</tr>
			<tr>
				<td>联系电话</td>
				<td><input type="text" class="input" autocomplete="off" name="contactPhone"/></td>
			</tr>
			<tr>
				<td>地址</td>
				<td><input type="text" class="input" autocomplete="off" name="address"/></td>
			</tr>
		</table>
	</div>

<script>

var requestParams = app.getRequestParams();
$(function () {
	$('#companyId').search({
		name:'companyId',
		click:function(){
			var index = parent.layer.getFrameIndex(window.name);
			app.window(parent.layer,{
				btn:[],
				area: ['600px', '450px'],
				content: '../../common/company_tree.html?index='+index+'&searchId=companyId'
			});
		}
	});

    var company = {companyId:app.getCompanyId(),companyId_text:app.getCompanyName()};
    app.resetForm(company);


    if(requestParams.id){
		app.request({
			url:'store/get',
			data:{id:requestParams.id},
			success:function(resp){
			if( resp.result==0 ){
				$('#formArea').append('<input type="hidden" value="'+requestParams.id+'" name="id"/>');
				//$('#fromArea input[name="companyId_text"]').val(requestParams.companyName);
				resp.data.companyId_text = requestParams.companyName;
				app.resetForm(resp.data)
			}else{
				app.message(parent.layer,'获取选中信息失败【'+resp.data+'】',2);
			}
		}
		});
	}
});

app.getOkBtn().click(function(){
	if( !checkForm() ){
		return;
	}

	var url = 'store/insert';

	if(requestParams.id){
		url = 'store/update'
	}
	app.request({
		url:url,
		data:app.serializeForm(),
		success:app.actionSuccess_parent
	});


});

function checkForm(){

	var checkOptions = [
		{type:'input',name:'name',verify:[{type:'required'}]},
		{type:'input',name:'contact',verify:[{type:'length',value:5}]
	}];

	return app.checkForm(checkOptions);
}

</script>

</body>
</html>